/**
 * Copyright (c) 2013 onionframework.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.onionframework.core;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author allan
 *
 */
@Component("onion")
public class Onion {

	private static Onion onion;
	
	@Autowired
	private ApplicationContext applicationContext;
	
	@PostConstruct
	public void init(){
		onion = this;
	}
	
	public static <T> T getBean(Class<T> clazz){
		return onion.applicationContext.getBean(clazz);
	}
	
	public static <T> T getBean(Class<T> clazz,String name){
		return onion.applicationContext.getBean(name,clazz);
	}
	
	public static Object getBean(String name,Object... args){
		return onion.applicationContext.getBean(name,args);
	}
	
	public static Object getBean(String name){
		return onion.applicationContext.getBean(name);
	}
	
	public static ApplicationContext getApplicationContext(){
		return onion.applicationContext;
	}
	
	public static Onion instance(){
		return onion;
	}
}
